---
title: Build a service response
summary: Accumulate categorized success/warning/error/environment messages for service-style callers.
status: draft
owner: SAIF Documentation
last_reviewed: 2026-08-26
library: SAIF.Application
reference_type: embedded
operation_id: build-a-service-response
trigger: A service-style manager derived from clsServiceAppManagerBase completes a unit of work
---

# Build a service response

Accumulates categorized success, warning, error, and environment messages into a `ServiceResponse` for
service-style managers, and converts caught exceptions into environment messages.

| Field | Value |
| --- | --- |
| **Operation ID** | build-a-service-response |
| **Trigger** | A service-style manager derived from `clsServiceAppManagerBase` completes a unit of work |
| **Inputs** | Messages added during processing; optionally a caught `Exception` |
| **Outputs** | `Result` flag plus categorized message collections |
| **Primary components** | `ServiceResponse` |
| **Entry point** | `SAIF.Application/Service Based/ServiceResponse.vb` |

## Steps

1. A new `ServiceResponse` starts with `Result = True` and an empty message list
   ([BR-APP-009](../business-rules.md#br-app-009-service-responses-succeed-until-declared-otherwise-exceptions-are-environmental)).
2. Processing code calls `AddErrorMessage` / `AddWarningMessage` / `AddInformationMessage` /
   `AddEnvironmentMessage`, each wrapping the text and optional key in a `ServiceMessage` of the
   corresponding `ServiceMessageType`.
3. On an exception, `ProcessException(ex)` records `ex.Message` keyed by `ex.GetType.Name` as an
   `Environment` message, then walks the inner-exception chain doing the same.
4. Consumers read `Errors`, `Warnings`, `InformationalMessages`, and `EnvironmentalErrors`, which are
   LINQ filters over the single ordered `Messages` list.
5. `Result` is a public field never modified by this class — the caller is responsible for setting it
   to `False` when errors are present
   ([BR-APP-009](../business-rules.md#br-app-009-service-responses-succeed-until-declared-otherwise-exceptions-are-environmental)).

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start(["ServiceResponse<br>created: Result=True"]) --> Process["Processing code adds<br>Error/Warning/Info/Env<br>messages"]
	Process --> Exception{"Exception<br>caught?"}
	Exception -->|Yes| ProcessEx["ProcessException:<br>walk inner-exception chain"]
	Exception -->|No| Read["Consumer reads<br>Errors/Warnings/Info/<br>EnvironmentalErrors"]
	ProcessEx --> Read
	Read --> SetResult["Caller sets Result<br>= False if needed"]
```

## Failure and edge-case behavior
- Defect: the inner-exception loop re-assigns `LocalEX = ex.InnerException` (the outer exception)
  instead of `LocalEX.InnerException`, so any exception with a non-`Nothing` inner exception causes an
  infinite loop that appends the same message repeatedly.**

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
